#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QGraphicsScene>
#include <QGraphicsPixmapItem>
#include "myitem.h"
#include <QPropertyAnimation>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    QGraphicsScene* scene = new QGraphicsScene(this);
    MyItem* myItem = new MyItem(this, QPixmap(":/images/default.png"));
    myItem->setTransformOriginPoint(myItem->boundingRect().center()); // 设置坐标系的原点
    scene->addItem(myItem);
    scene->addItem(new QGraphicsPixmapItem(QPixmap(":/images/magnetNeedle.png")));
    ui->graphicsView->setScene(scene);

    QPropertyAnimation* animation = new QPropertyAnimation(myItem, "rotation");
    animation->setDuration(30 * 1000);
    animation->setStartValue(0);
    animation->setEndValue(360);
    animation->setLoopCount(-1);
    animation->start();
}

MainWindow::~MainWindow()
{
    delete ui;
}
